package com.fan.admin.controller;


import com.fan.admin.service.ClaInfoService;
import com.fan.admin.service.CollegeInfoService;
import com.fan.admin.service.SystemInfoService;
import com.fan.commons.pojo.ClaInfo;
import com.fan.commons.pojo.CollegeInfo;
import com.fan.commons.pojo.SystemInfo;
import com.fan.commons.util.JsonResult;
import com.fan.commons.util.PageUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @author fan
 * @date 2021/1/26
 */
@Controller
public class InfoController {

	@Autowired
	private CollegeInfoService collegeInfoService;

	@Autowired
	private SystemInfoService systemInfoService;

	@Autowired
	private ClaInfoService claInfoService;

	@ResponseBody
	@GetMapping("/info/college")
	public JsonResult getCollegeInfo() {
		// 实际功能代码请完成...
		List<CollegeInfo> collegeInfos = collegeInfoService.queryCollegeInfo();
		return JsonResult.success(collegeInfos);
	}

	/**
	 * 根据传入的 collegeId 获取对应的 systemInfo 数据
	 *
	 * @param collegeId collegeId
	 * @return JsonResult
	 */
	@ResponseBody
	@GetMapping(value = "/info/system")
	public JsonResult getSystemInfo(String collegeId) {
		// 代码完成
		List<SystemInfo> systemInfoList = systemInfoService.querySystemInfo(collegeId);
		return JsonResult.success(systemInfoList);
	}

	@ResponseBody
	@GetMapping("/info/cla")
	public JsonResult getClaInfo(@Param(value = "1") Integer page, @Param(value = "5") Integer pageSize) {
		PageHelper.startPage(page, pageSize);
		List<ClaInfo> claInfos = claInfoService.queryCalInfo(null);
		PageInfo<ClaInfo> pageInfo = new PageInfo<>(claInfos);
		PageUtil pageUtil = new PageUtil(pageInfo.getPageNum(), pageInfo.getPageSize(), claInfos, pageInfo.getTotal());
		return JsonResult.success(pageUtil);
	}
}
